/**
 * Created by wzq on 15-3-28.
 */

var mongodb = require('./mongodb.js');
var Schema = mongodb.Schema;

var departmentSchema = new Schema({
	department_id: {
		type: Number,
		index: true,
		required: true,
		unique: true
	},
	department_name: String,
	parent_id: Number,
	order_in_parent: Number,
	created_at: Date,
	updated_at: {
		type: Date,
		default: Date.now
	}
});

departmentSchema.pre('save', function(next) {
	var currentDate = new Date();
	if (!this.created_at) {
		this.created_at = currentDate;
	}
	next();
});

var Department = mongodb.model('Department', departmentSchema);

module.exports = Department;
